#!/usr/bin/env python3
# 保存为 /var/www/cgi-bin/hello.py
# print("Content-Type: text/html\n")  # HTTP 头部，必须包含
# print("<html><body>")
# print("<h1>Hello, CGI!</h1>")
# print("</body></html>")


#!/usr/bin/env python3
 
# 输出 HTTP 头
# print("Content-Type: text/html\n")  # 必须包括一个空行
 
# # 输出 HTML 页面
# print("<html>")
# print("<head><title>Python CGI</title></head>")
# print("<body>")
# print("<h1>Welcome to Python CGI Programming</h1>")
# print("</body>")
# print("</html>")


#!/usr/bin/env python3
import cgi
 
# 解析表单数据
form = cgi.FieldStorage()
 
# 获取表单字段值
name = form.getvalue("name", "(no name provided)")
age = form.getvalue("age", "(no age provided)")
 
# 输出 HTTP 头和 HTML 内容
print("Content-Type: text/html\n")
print("<html><body>")
print(f"<h1>Hello, {name}!</h1>")
print(f"<p>Your age is {age}.</p>")
print("</body></html>")

